package com.example.android.bluetoothlegatt;

public class ByteUtil {

    public static String boolean2String(boolean bool) {
        return bool ? "1" : "0";
    }

    public static boolean string2Boolean(String number) {
        boolean bool = true;
        if ("0".equals(number)) {
            bool = false;
        }
        return bool;
    }
    public static String getByteStr(int num) {
        StringBuilder sb = new StringBuilder(Integer.toBinaryString(num));
        while (sb.length() < 32) {
            sb.insert(0, '0');
        }
        sb.insert(8, ',');
        sb.insert(16 + 1, ',');
        sb.insert(24 + 2, ',');
        return sb.toString();
    }

    public static String byte2hex(byte [] buffer){
        String h = "";

        for(int i = 0; i < buffer.length; i++){
            String temp = Integer.toHexString(buffer[i] & 0xFF);
            if(temp.length() == 1){
                temp = "0" + temp;
            }
            h = h + " "+ temp;
        }

        return h;

    }
}
